home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 114_01.zip / CONFIG2.BDS < prev    next >
Text File  |  1993-06-01  |  4KB  |  262 lines

  1. /* Screen editor:  configuration program utilities
  2.  *
  3.  * Source:  config2.bds
  4.  * Version: December 20, 1981.
  5.  */
  6.  
  7. #include bdscio.h
  8. #include config.h
  9.  
  10. /* print CR, LF and string to console */
  11.  
  12. plc(s) char *s;
  13. {
  14.  
  15.     putchar('\n');
  16.     puts(s);
  17. }
  18.  
  19. /* print string to console */
  20.  
  21. pc(s) char *s;
  22. {
  23.     puts(s);
  24. }
  25.  
  26. /* print yes or no on the console */
  27.  
  28. putyesno(n) int n;
  29. {
  30.     if (n==YES) {
  31.         pc("yes");
  32.     }
  33.     else if (n==NO) {
  34.         pc("no");
  35.     }
  36.     else {
  37.         pc("syserr");
  38.     }
  39. }
  40.  
  41. /* put blank line to console */
  42.  
  43. blank()
  44. {
  45.     plc("");
  46. }
  47.  
  48. /* start a new line and indent it */
  49.  
  50. indent()
  51. {
  52.     plc("    ");
  53. }
  54.  
  55. /* get decimal value from user */
  56.  
  57. getval(def) int def;    /* default */
  58. {
  59. int val;
  60. char buffer[81];    /* cp/m needs 81 chars */
  61.     while (1) {
  62.         plc("Enter decimal value or carriage return:  ");
  63.         gets(buffer);
  64.         if (buffer[0]==0) {
  65.             return(def);
  66.         }
  67.         else if (number(buffer,&val)==YES) {
  68.                 return(val);
  69.         }
  70.     }
  71. }
  72.  
  73. /* get a yes or no answer from the user */
  74.  
  75. yesno()
  76. {
  77. char buffer[81];
  78. char c;
  79.     while (1) {
  80.         pc("  ");
  81.         gets(buffer);
  82.         c=tolower(buffer[0]);
  83.         if (c=='y') {
  84.             return(YES);
  85.         }
  86.         else if (c=='n') {
  87.             return(NO);
  88.         }
  89.         else {
  90.             plc("answer yes or no.");
  91.         }
  92.     }
  93. }
  94.  
  95. /* get each byte of a control sequence */
  96.  
  97. getbytes(index) int *index;
  98. {
  99. char buffer[81];
  100. char c;
  101. int k;
  102. int j;
  103.     *index=bytec;
  104.     /* do until user says all is well */
  105.     while (1) {
  106.         plc("");
  107.         k=0;
  108.         bytec=*index;
  109.         /* do until no more bytes */
  110.         while (1) {
  111.             pc("Enter byte ");
  112.             putdec(++k,3);
  113.             pc(":  ");
  114.             gets(buffer);
  115.             if (buffer[0]==0) {
  116.                 bytes[bytec++]=0;
  117.                 break;
  118.             }
  119.             /* put bytes into bytes[] */
  120.             j=0;
  121.             while (bytec<BYTEMAX) {
  122.                 c=buffer[j++];
  123.                 bytes[bytec++]=c;
  124.                 if (c==0) {
  125.                     break;
  126.                 }
  127.             }
  128.             if (bytec>=BYTEMAX) {
  129.                 plc("byte buffer overflow.");
  130.                 return;
  131.             }
  132.         }
  133.         pc("Are all bytes correct ?");
  134.         if (yesno()==YES) {
  135.             return;
  136.         }
  137.     }
  138. }
  139.  
  140. /* file utilities */
  141.  
  142. /* write one byte to the current output file */
  143.  
  144. putfile(c) char c;
  145. {
  146.     return (putc(c,outbuf));
  147. }
  148.  
  149. /* write CR, LF and string to current output file */
  150.  
  151. plf(s) char *s;
  152. {
  153.     putfile(CR);
  154.     putfile(LF);
  155.     pf(s);
  156. }
  157.  
  158. /* write string to current output file */
  159.  
  160. pf(s) char *s;
  161. {
  162.     while (*s!=0) {
  163.         putfile(*s++);
  164.     }
  165. }
  166.  
  167. /* write start of comment to output file */
  168.  
  169. comment()
  170. {
  171.     plf("/*");
  172. }
  173.  
  174. /* write end of comment to output file */
  175.  
  176. endcom()
  177. {
  178.     plf("*/");
  179. }
  180.  
  181. /* write blank line to output file */
  182.  
  183. blankf()
  184. {
  185.     plf("");
  186. }
  187.  
  188. /* write 1 tab on new line to output file */
  189.  
  190. tab1f()
  191. {
  192.     putfile(CR);
  193.     putfile(LF);
  194.     putfile(TAB);
  195. }
  196.  
  197. /* write 2 tabs on new line to output file */
  198.  
  199. tab2f()
  200. {
  201.     putfile(CR);
  202.     putfile(LF);
  203.     putfile(TAB);
  204.     putfile(TAB);
  205. }
  206.  
  207. /* write start of procedure body to output file */
  208.  
  209. beginf()
  210. {
  211.     plf("{");
  212. }
  213.  
  214. /* write end of procedure body to output file */
  215.  
  216. endf()
  217. {
  218.     plf("}");
  219. }
  220.  
  221. /* write #define statement to output file */
  222.  
  223. putdef(s,n) char *s; int n;
  224. {
  225. char buffer[10];
  226.     plf("#define ");
  227.     pf(s);
  228.     pf(" ");
  229.     itoc(n,buffer,10);
  230.     pf(buffer);
  231. }
  232.  
  233. /* generate code to do special screen functions.
  234.  * index points into bytes[].
  235.  */
  236.  
  237. putbytes(index) int index;
  238. {
  239.     while (bytes[index]!=0) {
  240.         if (index>BYTEMAX) {
  241.             plf("syserr: putbytes");
  242.             return;
  243.         }
  244.         tab1f();
  245.         pf("syscout(");
  246.         while (bytes[index]!=0) {
  247.             putfile(bytes[index++]);
  248.         }
  249.         index++;
  250.         pf(");");
  251.     }
  252. }
  253. ndcom()
  254. {
  255.     plf("*/");
  256. }
  257.  
  258. /* write blank line to output file */
  259.  
  260. blankf()
  261. {
  262.     p